<?php

namespace App\Admin\Extensions\ExcelExport;

use Encore\Admin\Grid\Exporters\AbstractExporter;
use Maatwebsite\Excel\Facades\Excel;

class TeamExpoter extends AbstractExporter
{
    public function export()
    {
        ini_set('memory_limit','500M');
        set_time_limit(0);//设置超时限制为0分钟
        Excel::create('团队表', function($excel) {
            $excel->sheet('团队', function($sheet) {
                // 这段逻辑是从表格数据中取出需要导出的字段
                $rows = collect($this->getData())->map(function ($item) {
                    return array_only($item, ['name', 'sex', 'card_type','id_card','birthday','team_id','origin','destination','guide','travel_agency','hotel','transport_company','car_id','driver','arrive_date','leave_date']);
                });
                $sheet->prependRow(['姓名', '性别', '证件类型','证件号','生日','团队号','客源地','目的地','导游','旅行社','酒店','客运公司','车牌号','随车司机','抵达日期','离开日期']);
                $sheet->row(1, function($row) {
                    $row->setAlignment('center');
                    $row->setFont(array(
                        'size'       => '12',
                        'bold'       =>  true
                    ));
                });
                $sheet->rows($rows);
            });
        })->export('xls');
    }
}